package com.wlk.service.impl;

import com.wlk.Result.Result;
import com.wlk.mapper.UsersMapper;
import com.wlk.pojo.Users;
import com.wlk.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wlk
 */
@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    private UsersMapper usersMapper;

    public List<Users> selectUsers() {
        return usersMapper.selectUsers();
    }

    @Override
    public Result getUserByPhoneAndPassword(String phone, String password) {
       //1.校验手机号是否格式正确，不正确直接返回登录信息格式错误
        if (phone == null || phone.toString().length() != 11) {
            return Result.fail("手机号格式错误");
        }else{
            //手机号格式正确，继续校验密码是否正确
            Users user = usersMapper.getUserByPhoneAndPassword(phone, password);
            return Result.ok(user);
        }
        //2.格式正确校验用户信息是否能够找到，找不到直接返回登录信息不存在

        //3.如果找到用户信息，校验密码是否正确，正确返回用户信息，错误返回登录信息密码错误



    }
}
